package com.mm.mindmap.handler;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.mm.common.pipeline.PipelineHandler;
import com.mm.common.pipeline.Product;
import com.mm.mindmap.chache.MindMapCache;
import com.mm.mindmap.domain.dto.MindMapDTO;
import com.mm.mindmap.domain.po.MindMap;
import com.mm.mindmap.mapper.MindMapMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * @Program: 8.mindmap
 * @Author: 海里的鱼
 * @Create: 2024-08-15 11:32
 * @Name:
 * @Desc: TODO
 */

@Component
@RequiredArgsConstructor
public class ViewIncrement extends PipelineHandler {
    private final MindMapMapper mindMapMapper;
    private final MindMapCache mindMapCache;

    @Override
    public Product process(Product product){
        MindMapDTO mindMap = product.getData(MindMapDTO.class);
        //访问量+1
        LambdaUpdateWrapper<MindMap> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.setSql("`view` = `view`+1").eq(MindMap::getId,mindMap.getId());
        mindMapMapper.update(null,updateWrapper);
        mindMap.setView((mindMap.getView()+1));

        //修改缓存
        mindMapCache.addOrUpdateMindMap1(mindMap);
        return product;
    }
}
